﻿package roleView
{
	import core.ColorSprite;
	import core.IColorContainer;
	import flash.display.DisplayObjectContainer;
	import flash.events.DataEvent;
	
	public class ColorItem extends ColorSprite
	{
		private var owner:IColorContainer;
		
		public function ColorItem()
		{
			initOwner();
		}
		
		
		private function initOwner():void
		{
			var p:DisplayObjectContainer = this.parent;
			while (p)
			{
				
				if (p is IColorContainer)
				{
					owner = p as IColorContainer;
					owner.addEventListener(ColorItemConst.COLOR_CHANGED, onColorChanged);
					this.color = owner.color;
					
					
					
					break;
				}
				p = p.parent;
			}
		}
		
		private function onColorChanged(e:DataEvent):void 
		{
			this.color = uint(e.data);
		}
		
	}
		
}